<template>
  <div class="vue-box sbot sbot-fluid">
    <!-- 参数栏 -->
    <div class="c-panel">
      <el-form :inline="true">
        <!-- 表单 -->
        <sa-item v-model="m.name" type="text" name="字典项" br />
        <sa-item v-model="m.code" type="text" name="编码" br />
        <sa-item v-model="m.icon" type="img" name="图标" br />
        <sa-item v-model="m.status" type="enum" jtype="3" :jv="dims.YES_OR_NO" name="启用状态" br />
        <sa-item v-model="m.note" type="text" name="描述" br />
        <sa-item v-model="m.sort" type="text" name="序号" br />
        <sa-item name="" br class="s-ok">
          <el-button type="primary" icon="el-icon-plus" @click="ok()">保存</el-button>
        </sa-item>
      </el-form>
    </div>
  </div>
</template>

<script>

export default {
  name: 'dict-item-add',
  props: { param: Object },
  data() {
    return {
      // 超级对象
      m: this.createModel(),
      dims: sa.$sys.getCurd(),
    }
  },
  created: function () {
  },
  methods: {
    createModel() {
      return {
        id: this.param.id,
        name: this.param.name,
        code: this.param.code,
        icon: this.param.icon,
        status: this.param.status,
        dictId: this.param.dictId,
        note: this.param.note,
        sort: this.param.sort
      }
    },
    // 变更
    ok: function () {
      // 表单校验
      sa.checkNull(this.m.name, '请输入条目名');
      sa.checkNull(this.m.code, '请输入条目码');
      sa.checkNull(this.m.status, '请确认状态');
      // 添加
      let url;
      if (this.m.id) {
        url = '/dict/item/update'
      } else {
        url = '/dict/item/add'
      }
      sa.ajax(url, this.m, function (res) {
        if (res.code == 200) {
          sa.alert(res.msg, function () {
            this.m = this.createModel();
            sa.closeModel();
            sa.currView().f5();
          }.bind(this));
        }
      }.bind(this), { type: 'post' });
    }
  }
}
</script>

<style scoped></style>